<?php
session_start();
header('Content-type: text/html; charset=utf-8');
include($_SERVER["DOCUMENT_ROOT"]."/public/function.php");
$config = include($_SERVER["DOCUMENT_ROOT"]."/public/config.php");

$name=$_POST['name'];
$pass=$_POST['pass'];
$youxiang=$_POST['youxiang'];
$shouji=$_POST['shouji'];

$yzm=$_POST['yzm'];
$yanz=$_SESSION['yanz'];

//$rese = selec($config,'haoyou',"where `name` = '$name'");
if(strcasecmp($_POST['yzm'], $_SESSION['yanz'])){
        echo"<script>alert('验证码错误！');history.go(-1);</script>";
        die;
    }elseif($_POST['pass']!=$_POST['passw']){
        echo '<script>alert("您填写密码有误！");history.go(-1);</script>';
        die;
    }else{
        @mysql_connect ('localhost','root','root');

        if(mysql_errno()){
            die(mysql_error());
        }
        mysql_select_db('bolgme');
        mysql_set_charset('utf8');
        $sql = "select name from haoyou where `name` = '$_POST[name]'"; 
        $rese = mysql_query($sql); 
        $num = mysql_num_rows($rese);//函数返回结果集中行的数目

        if($num){
                echo "<script>alert('用户名已存在'); history.go(-1);</script>";
            }else{
                //$pass=md5($pass);
                $arr = array('name'=>$name,'pass'=>$pass,'youxiang'=>$youxiang,'shouji'=>$shouji);
                $res = add($config,'haoyou',$arr);
                if($res){
                        echo '<script>alert("注册成功！");window.location.href="login.php"</script>';
                     }else{
                         echo '<script>alert("注册失败！");history.go(-1);</script>';
                        die;
            }
            }
    }
session_destroy();

?>